import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class MyHttpClient {
    public static void main(String[] args) throws IOException, InterruptedException {
        //创建一个httpClient对象
        //使用工厂方法去创建实例
        HttpClient client=HttpClient.newHttpClient();
        //创建一个HttpRequest,表示一个http请求
        HttpRequest request= HttpRequest.newBuilder()
                .uri(URI.create("https://www.sogou.com"))
                .GET()
                .header("User-Agent","xxx")
                .build();
        //发送请求，等待响应
        //send执行之后就进去了阻塞，直到响应返回回来了
        HttpResponse<String> response=client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode());
        System.out.println(response.headers());
        System.out.println(response.body());
    }
}
